#include <cstdio>
#include <vector>
typedef long long ll;

struct Query {
  int l, r, id, opt;
  ll c;
};

struct Node {
  int laz, sum;
  bool cle;
};

const int N = 50005;
int n, m, cnt;
int ans[N];
Query q[N], lq[N], rq[N];
Node tr[N << 2];

inline void pushup(int x) { tr[x].sum = tr[x << 1].sum + tr[x << 1 | 1].sum; }

inline void pushdown(int x, int l, int r) {
  static int ls, rs, mid;
  ls = x << 1, rs = x << 1 | 1, mid = (l + r) >> 1;
  if (tr[x].cle) {
    tr[x].cle = false;
    tr[ls].cle = true, tr[rs].cle = true;
    tr[ls].laz = tr[rs].sum = 0, tr[ls].sum = tr[rs].laz = 0;
  }
  if (tr[x].laz) {
    tr[ls].laz += tr[x].laz;
    tr[rs].laz += tr[x].laz;
    tr[ls].sum += tr[x].laz * (mid - l + 1);
    tr[rs].sum += tr[x].laz * (r - mid);
    tr[x].laz = 0;
  }
}

void modify(int x, int l, int r, int L, int R, int val) {
  if (L <= l && r <= R) {
    tr[x].laz += val;
    tr[x].sum += val * (r - l + 1);
    return;
  }
  int mid = (l + r) >> 1;
  pushdown(x, l, r);
  if (L <= mid) modify(x << 1, l, mid, L, R, val);
  if (mid < R) modify(x << 1 | 1, mid + 1, r, L, R, val);
  pushup(x);
}

int query(int x, int l, int r, int L, int R) {
  if (L <= l && r <= R) {
    return tr[x].sum;
  }
  int mid = (l + r) >> 1, res = 0;
  pushdown(x, l, r);
  if (L <= mid) res += query(x << 1, l, mid, L, R);
  if (mid < R) res += query(x << 1 | 1, mid + 1, r, L, R);
  return res;
}

void solve(int ql, int qr, int l, int r) {
  if (l == r) {
    for (int i = ql; i <= qr; ++i) {
      if (q[i].opt == 2) ans[q[i].id] = l;
    }
    return;
  }
  int lqh = 0, rqh = 0;
  int mid = (l + r) >> 1;
  bool fll = false, flr = false;
  tr[1].cle = true;
  tr[1].laz = tr[1].sum = 0;
  for (int i = ql; i <= qr; ++i) {
    if (q[i].opt == 1) {
      if (q[i].c > mid) {
        modify(1, 1, n, q[i].l, q[i].r, 1);
        rq[++rqh] = q[i];
      } else {
        lq[++lqh] = q[i];
      }
    } else {
      unsigned int k = query(1, 1, n, q[i].l, q[i].r);
      if (k < q[i].c) {
        q[i].c -= k;
        lq[++lqh] = q[i];
        fll = true;
      } else {
        rq[++rqh] = q[i];
        flr = true;
      }
    }
  }
  for (int i = 1; i <= lqh; ++i) {
    q[ql + i - 1] = lq[i];
  }
  for (int i = lqh + 1; i <= lqh + rqh; ++i) {
    q[ql + i - 1] = rq[i - lqh];
  }
  if (fll) solve(ql, ql + lqh - 1, l, mid);
  if (flr) solve(ql + lqh, qr, mid + 1, r);
}

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("OverallDiv.in", "r", stdin);
  freopen("OverallDiv.out", "w", stdout);
#endif
#endif

  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d%d%lld", &q[i].opt, &q[i].l, &q[i].r, &q[i].c);
    if (q[i].opt == 2) q[i].id = ++cnt;
  }
  solve(1, m, -n, n);
  for (int i = 1; i <= cnt; ++i) {
    printf("%d\n", ans[i]);
  }
  return 0;
}